use ggez::{Context, GameResult, GameError, graphics, mint::Point2};

pub struct State{
}

impl State{
    pub fn new() -> State {
        State{}
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, _ctx: &mut Context) -> GameResult {
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);
        let mut points: Vec<Point2<f32>> = vec![];
        for i in 0..800 {
            let x = i as f32;
            let y = (x*0.05).sin()*300.0 + 300.0;
            let p = Point2{x, y};
            points.push(p);
        }
        let poliline = graphics::Mesh::new_polyline(
            ctx, 
            graphics::DrawMode::stroke(2.0), 
            points.as_slice(), 
            graphics::Color::BLACK).unwrap();
        canvas.draw(&poliline, graphics::DrawParam::default());        
        
        canvas.finish(ctx)?;
        Ok(())
    }
}